//关于管理的操作
//包括登录,注册,删除书籍,添加书籍,修改书籍,退出登录等

import request from "./request";

//管理员登录
export function adminLogin(adminObj) {
  return request.post('login',{
    username:adminObj.username,
    password:adminObj.password,
  })
}

//管理员注册
//这里的userKind字段我们直接固定为1
export function adminRegister(adminObj) {
  console.log(adminObj);
  return request.post('add_user',{
    username:adminObj.username,
    password:adminObj.password,
    nickname:adminObj.nickname,
    userPortrait: adminObj.cover,
    userKind: 1
    // adminPortrait: adminObj.adminIcon,
    // realName: adminObj.realName,
    // adminPhone: adminObj.phone,
  })
}

// 管理员更新
export function adminUpdate(adminObj) {
  return request.post('update_user',{
    id:adminObj.username,
    username:adminObj.username,
    password:adminObj.password,
    nickname:adminObj.nickname,
    userPortrait: adminObj.adminIcon
    // adminSex: adminObj.sex,
    // adminPortrait: adminObj.adminIcon,
    // realName: adminObj.realName,
    // adminPhone: adminObj.phone,
  })
}


//获取全部管理员
export function adminAll() {
  return request.get(`find_user_by_kind?userKind=1`);
}

//使用用户名查询用户
export function getUserById(id){
  return request.get(`find_user_by_id?id=${id}`);
}

//上传接口
export function imageUpload(file){
  return request.post('image_upload',{
    file
  });
}

//根据用户名删除接口
export function delByUserName(username) {
  return request.post('/admin/delete',{
    username
  });
}

//根据用户名查询详情照片
export function getDetailByUserName(username){
  return request.get(`/api/admin/findbyname?adminName=${username}`);
}

